package com.bawei.common.model

import com.bawei.common.api.BaseApiServer
import com.bawei.net.HttpInterceptorType
import com.bawei.net.HttpManager

/**
 * Author: Jason Zhang
 * Date: 2024/12/12
 * Desc: 基础数据仓库
 */
abstract class BaseRepository<T: BaseApiServer> {
    private var tokenApiServer: T? = null
    private var signApiServer: T? = null
    private var uploadApiServer: T? = null
    private var commonApiServer: T? = null

    fun <T> createApiServer(clazz: Class<T>, type: HttpInterceptorType): T {
        return when(type){
            HttpInterceptorType.TOKEN -> (tokenApiServer ?: HttpManager.createApiServer(clazz, type)) as T
            HttpInterceptorType.SIGN -> (signApiServer ?: HttpManager.createApiServer(clazz, type)) as T
            HttpInterceptorType.UPLOAD -> (uploadApiServer ?: HttpManager.createApiServer(clazz, type)) as T
            HttpInterceptorType.COMMON -> (commonApiServer ?: HttpManager.createApiServer(clazz, type)) as T
        }
    }

}